#define LINUX
#ifndef __FTPSERVER_H__
#define __FTPSERVER_H__

#include "FtpClient.h"

#define MAX_CLIENTS 50

typedef struct Userlog{
	struct Userlog* userlog_Next;
	char m_Username[32];
	char m_Password[32];

} Userlog;


typedef struct FtpServer
{
	int socket;
	int port;
	int m_iAnonymous; // != 0 if anonymous logins are allowed
	Userlog* userList;
	FtpClientContainer m_kClients;
	FtpClient m_kClientArray[MAX_CLIENTS];
} FtpServer;

#define FtpServer_ClientTraverse(server) \
	{ \
		FtpClientContainer* pClientNext; \
		FtpClientContainer* pClientContainer = (server)->m_kClients.m_pNext; \
		while( pClientContainer != &((server)->m_kClients) ) \
		{ \
			FtpClient* pClient = pClientContainer->m_pClient; \
			pClientNext = pClientContainer->m_pNext;

#define FtpServer_ClientEndTraverse \
			pClientContainer = pClientNext; \
		} \
	}

void FtpServer_Create( FtpServer* pServer );
void FtpServer_Destroy( FtpServer* pServer );
int FtpServer_Start( struct FtpServer* pServer );
void FtpServer_Stop( struct FtpServer* pServer );

void FtpServer_SetPort( FtpServer* pServer, int iPort );
void FtpServer_SetAnonymous( FtpServer* pServer, int iAnonymous );
void FtpServer_SetUsername( FtpServer* pServer, char* pUsername );
void FtpServer_SetPassword( FtpServer* pServer, char* pPassword );
void FtpServer_SetUserlist(FtpServer* pServer, char* userlist);

int FtpServer_IsRunning( struct FtpServer* pServer );
int FtpServer_HandleEvents( struct FtpServer* pServer );
FtpClient* FtpServer_OnClientConnect( struct FtpServer* pServer, int iSocket );
void FtpServer_OnClientDisconnect( struct FtpServer* pServer, FtpClient* pClient );

#endif
